<?php if (!defined('THINK_PATH')) exit();?><!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>添加商品</title>
	<link rel="stylesheet" href="/Public/Admin/Css/Goods/savaSlide.css">
	<script src="/Public/Admin/Js/jquery.js"></script>
     <script src='/Public/jquery.uploadify.min.js'></script>
     <script src="/Public/Home/Js/GetRequest.js"></script>
</head>
<body>
	<div id="content_box">
		<table border=1>
		<form id="slide_form">
			<tr>
				<td>广告位置：</td>
				<td>
					<select id="category" name="cid">

					</select>
				</td>
			</tr>

			<tr>
				<td>链接地址：</td>
				<td><input id="links" name="links" type="text" required="required"></td>
			</tr>

			<tr>
				<td>是否显示：</td>
				<td>
					<label for="displays1"><input name="display" id="displays1" required="required" type="radio" checked value="1">显示</label>
					<label for="displays2"><input name="display" id="displays2" required="required" type="radio" value="2">不显示</label>
				</td>
			</tr>

			<tr>
				<td>打开方式：</td>
				<td>
					<select name="opentype" id="opentype">
						<option value="1">新窗口打开</option>
						<option value="2">父窗口打开</option>
						<option value="3">当前窗口打开</option>
						<option value="4">顶级窗口打开</option>
					</select>
				</td>
			</tr>

			<tr>
				<td>广告排序：</td>
				<td>
					<input name="orders" id="orders" type="text" required="required">
				</td>
			</tr>

			<tr>
				<td colspan="3" style="text-align:center;">
					<input id="subbtn" type="button" value="提交">
				</td>
			</tr>
		</form>
		</table>

		<div id="img_right">
			<img src="/Public/Admin/Images/ico.ooopic.com.png" class="img_logo" title="">
			<input id="file_upload" name="file_upload" type="file" value="">
		</div>
	</div>
</body>
<script>

	$.get("/index.php/Admin/SavaSlide/category",function(data){
		add_options(data);
	},"json");

	//加载页面时，自动请求数据
	$.get("/index.php/Admin/SavaSlide/cateInfo?id="+Request['id'],function(data){

		$("#category").find("option[value='"+data['cid']+"']").attr("selected",true);

		$("#links").val(data['links']);

		switch(parseInt(data['display'])){
			case 1: $("display1").attr("checked",true);break;
			case 0: $("display2").attr("checked",true);break;
		}

		switch(parseInt(data['opentype'])){
			case 1 : $("#opentype").find("option[value='1']").attr("selected",true);break;
			case 2 : $("#opentype").find("option[value='2']").attr("selected",true);break;
			case 3 : $("#opentype").find("option[value='3']").attr("selected",true);break;
			case 4 : $("#opentype").find("option[value='4']").attr("selected",true);break;
		}

		$("#orders").val(data['orders']);

		$(".img_logo").attr("title",data['address']);
		$(".img_logo").attr("src","/Public/Home/Images/slide/"+data['address']);
	},"json");

	function add_options(data){
		var options = "";
		options += "<option value='0'>首页</option>";
		for(var i=0;i<data.length;i++){
			options += "<option value=\""+data[i]['id']+"\">"+data[i]['name']+"</option>";
		}
		$("#category").empty().append(options);
	}



//----------------------------------------------------------------------------------------------

	for(var i=0;i<$("input[type='text']").length;i++){
		$("input[type='text']")[i].index = i;
		$("input[type='text']").eq(i).blur(function(){
			if($(this).val() == ""){
				$(this).css("border-bottom-color","red");
				$(this).attr("placeholder","此项为必填项");
			}else{
				$(this).css("border-bottom-color","#A8732F");
			}
		});
	}

	// 提交按钮
	$("#subbtn").click(function(){
		var v_data = $("#slide_form").serialize()+"&address="+$(".img_logo").attr("title")+"&id="+Request['id'];
				alert(v_data);
		if($(".img_logo").attr("title") == ""){
			alert("请选择商品图片！");
			return false;
		}else{
			if($("input[type='text']").val() != ""){
				$.ajax({
		               url: "getUpdate",     
		               data: v_data,  
		               type:"post",  
		               async: false,
		               success: function(data) {
		                   alert(data['info']);
		                   location.href = "/index.php/Admin/" + data['url'];
		               },
		               error: function(data) {
		               	alert("添加广告失败，请重试！");
		               }
		           });
			}else{
				alert("亲,请将广告信息填写完整！^_^");
			}	
		}
	});


		$('#file_upload').uploadify({
	        	'swf'      : '/Public/uploadify.swf',
	        	'uploader' : '<?php echo U("AddSlide/upload");?>',
	        	'buttonText' : '',
	        	 'multi'    : false,
	        	'onUploadSuccess' : function(file, data, response) {
	            $(".img_logo").attr("src","/Public/Home/Images/slide/"+data.substring(0,17));
	            $(".img_logo").attr("title",data.substring(0,17));
        	}
    	});


	//设置flash插件属性
	$("#chajian").css({"position":"relative","overflow":"hidden"});
	$("#SWFUpload_0").attr("height",$(".img_logo").height());
	$("#SWFUpload_0").attr("width",$(".img_logo").width());
	$("#SWFUpload_0").removeAttr("style");
	$("#SWFUpload_0").css({"position":"absolute","top":"50px","right":"90px","cursor":"pointer"});
	$("#file_upload").removeAttr("style");
	$("#file_upload").css({"background":"red","overflow":"hidden"});
	$("#file_upload-button").removeAttr("style");
	$("#file_upload-button").css("display","none");
	$("#file_upload-queue").removeAttr("class");
	$("#file_upload-queue").removeAttr("id");
	$("#SWFUpload_0").attr("onfocus","this.blur()");
		
</script>
</html>